<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
#parse("/linkandscript.html")
<title>论坛控</title>
</head>
<body>
<div id="importdiv">
    <textarea id="jsonstr" name="forumjson" style="width:100%; height:50px"></textarea>
    <a id="importbtn" class="btn btn-info">导入此论坛</a>
    <a id="batchimportbtn" class="btn btn-info">批量导入</a>
</div>

<style>
#importdiv{
	padding: 4px 20px 4px;
	text-align:center;
}
</style>
<script language="javascript">
$(function(){
	$("#importbtn").click(function(){
		var jsonstr = $("#jsonstr").val();
		console.log(jsonstr);

		$.post("/hezi/forum?action=savenewforum",
		  { 
		  	forumjson: jsonstr
		  },
		  function(returndata){
			  console.log("back:" + returndata);
			  consolelog(returndata);
			  $("#savebtn").addClass("btn-info");
		});
	});	
	
	$("#batchimportbtn").click(function(){
		var jsonstr = $("#jsonstr").val();
		console.log(jsonstr);

		$.post("/hezi/forum?action=batchimport",
		  { 
		  	forumjson: jsonstr
		  },
		  function(returndata){
			  console.log("back:" + returndata);
			  consolelog(returndata);
			  $("#savebtn").addClass("btn-info");
		});
	});	
	
})
</script>







<div id="forumlist">
你可以“从以下论坛中选择一个作为模板来修改” 或者 <a id="createfromnone">“直接从零填写”</a>
    <table id="forumlisttable" style="border:#CCC 1px solid; padding:2px;">
      <tr>
        <td>序号</td>
        <td>网站名称</td>
        <td>域名</td>
        <td>帖子格式</td>
        <td>帖子标题格式</td>
        <td>url包含关键字</td>
        <td>论坛地址格式</td>
      </tr>
    #set($i = 0)        
    #foreach($item in $sites) 
    #set($i = $i+1)
      <tr id="$item">
        <td>$i</td>
        <td class="sitename">$item.getSitename()</td>
        <td class="siteid" style="display:none">$item.getId()</td>
        <td class="domain">$item.getDomain()</td>
        <td class="trp">$item.getTrp()</td>
        <td class="titlep">$item.getTitlep()</td>
        <td class="urlkeyword">$item.getUrlkeyword()</td>
        <td class="urlp">$item.getUrlp()</td>
        <td class="contentp" style="display:none">$item.getContentp()</td>
      </tr>
    #end<!--end of group-->
    </table>
</div>


<div id="newforumdiv" style="display:none">
    <table width="80%" border="0" class="center">
      <tr>
        <td>网站名称</td>
        <td><input id="sitename" type="text" style="width:100px"/></td>
        <td>网站ID</td>
        <td><input id="siteid" type="text" style="width:100px"/></td>
      </tr>
      
      <tr>
        <td>版块名称</td>
        <td><input id="forumname" type="text" value="" style="width:100px"/></td>
        <td>版块数字</td>
        <td><input id="forumcode" type="text" value="" style="width:100px"/></td>
      </tr>
      
      <tr>
        <td>版块ID</td>
        <td><input id="forumid" type="text" value="" style="width:100px"/></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      

       


      <tr>
        <td>域名</td>
        <td colspan="3"><input id="domain" type="text" style="width:400px"/></td>
      </tr>
      <tr>
        <td>论坛地址格式</td>
        <td colspan="3"><input id="urlp" type="text" style="width:800px"/></td>
      </tr>
      <tr>
        <td>帖子格式</td>
        <td><input id="trp" type="text" style="width:100px"/></td>
        <td>帖子标题格式</td>
        <td><input id="titlep" type="text" style="width:100px"/></td>
      </tr>

      <tr>
        <td>URL包含关键字</td>
        <td><input id="urlkeyword" type="text" style="width:100px"/></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>帖子内容格式</td>
        <td colspan="3"><input id="contentp" type="text" style="width:400px"/></td>
      </tr>
      
      
      <tr>
        <td>分组</td>
        <td><input id="groups" type="text" style="width:100px" value="图片"/></td>
        <td>喜爱程度</td>
        <td><input id="priority" type="text" value="60" style="width:100px"/></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    
      
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>
        	<a id="trybtn" class="btn btn-info">试运行一下</a> 
        	<a id="savebtn" class="btn btn-info">保存</a>
        </td>
        <td>&nbsp;</td>
      </tr>
    </table>
</div>
</body>
<script language="javascript">
$(function(){
	

	$("#forumlisttable tr").click(function(){
		var sitename = $(this).find(".sitename").html();
		console.log(sitename);
		$("#sitename").val(sitename);
		$("#siteid").val($(this).find(".siteid").html());
		$("#domain").val($(this).find(".domain").html());
		$("#trp").val($(this).find(".trp").html());
		$("#titlep").val($(this).find(".titlep").html());
		$("#urlkeyword").val($(this).find(".urlkeyword").html());
		$("#urlp").val($(this).find(".urlp").html());
		$("#contentp").val($(this).find(".contentp").html());
		
		
		$("#forumlisttable").hide();
		$("#newforumdiv").show();
		
		
		
	});	
	
	
	$("#forumcode").blur(function(){
		forumcode = $(this).val();
		siteid = $("#siteid").val();
		$("#forumid").val(siteid+forumcode);
	});
	
	$("#createfromnone").click(function(){
		$("#forumlisttable").toggle();
		$("#newforumdiv").show();
	});	
	
	$("#trybtn").click(function(){
		var site = {};
		site.id = $("#siteid").val();
		site.name = $("#sitename").val();
		site.domain = $("#domain").val();
		site.urlp = $("#urlp").val();
		site.trp = $("#trp").val();
		site.titlep = $("#titlep").val();
		site.urlkeyword = $("#urlkeyword").val();
		site.contentp = $("#contentp").val();
		
		var forum = {};
		forum.site = site;
		forum.id = $("#forumid").val();
		forum.code = $("#forumcode").val();
		forum.name = $("#forumname").val();
		forum.groups = $("#groups").val();
		forum.priority = $("#priority").val();
		
		
		console.log("site json:");
		console.log(site);		
		console.log("forum json:");
		console.log(forum);	
		
		$.post("/hezi/forum?action=submittryrun",
		  { 
		  	forumjson: JSON.stringify(forum)
		  },
		  function(returndata){
			  console.log("back:" + returndata);
			  window.location.href="/hezi/scan?forum=tryrun&windowwidth="+$(window).width(); 
		});
	});	
	
	
	$("#savebtn").click(function(){
		var forum = prepareForumJson();
		
		$("#savebtn").removeClass("btn-info");
		$.post("/hezi/forum?action=savenewforum",
		  { 
		  	forumjson: JSON.stringify(forum)
		  },
		  function(returndata){
			  console.log("back:" + returndata);
			  $("#savebtn").addClass("btn-info");
		});
	});	
	
	
	
	
	
	
})

function prepareForumJson(){
		var site = {};
		site.id = $("#siteid").val();
		site.name = $("#sitename").val();
		site.domain = $("#domain").val();
		site.urlp = $("#urlp").val();
		site.trp = $("#trp").val();
		site.titlep = $("#titlep").val();
		site.urlkeyword = $("#urlkeyword").val();
		site.contentp = $("#contentp").val();
		
		var forum = {};
		forum.site = site;
		forum.id = $("#forumid").val();
		forum.code = $("#forumcode").val();
		forum.name = $("#forumname").val();
		
		forum.groups = $("#groups").val();
		forum.priority = $("#priority").val();
		
		
		console.log("site json:");
		console.log(site);		
		console.log("forum json:");
		console.log(forum);	
		
		return forum;
}

</script>

<style>
#forumlisttable tr:hover{
	background:#999;
}

</style>


</html>